package com.yc.game.cms.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yc.game.cms.dao.TrainingContentMapper;
import com.yc.game.cms.dao.TrainingMapper;
import com.yc.game.cms.dao.TrainingVoMapper;
import com.yc.game.cms.pojo.Training;
import com.yc.game.cms.pojo.TrainingContent;
import com.yc.game.cms.service.TrainingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TrainingServiceImpl implements TrainingService {
    @Autowired
    private TrainingMapper trainingMapper;
    @Autowired
    private TrainingContentMapper trainingContentMapper;
    @Override
    public int update(Training training) {
        Training newTraining = new Training();
        newTraining.setId(training.getId());
        newTraining.setStatus(training.getStatus());
        return trainingMapper.updateByPrimaryKeySelective(newTraining);
    }

    /**
     * 根据id删除
     * @param trainingId
     * @return
     */
    @Override
    public int delete(Integer trainingId) {
        return trainingMapper.deleteByPrimaryKey(trainingId);
    }

    /**
     * 查询所有
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<TrainingContent> getAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<TrainingContent> trainings = trainingContentMapper.getAll();
        PageInfo<TrainingContent> pageInfo = new PageInfo<>(trainings);
        return pageInfo;
    }
}
